package com.neuronbit.businessflow.intellij.editor.codec;

import com.mxgraph.io.mxObjectCodec;
import com.neuronbit.businessflow.intellij.model.Param;
import com.neuronbit.businessflow.intellij.model.ParamValue;

/**
 * The type Param codec.
 */
public class ParamCodec extends mxObjectCodec {
    /**
     * Instantiates a new Param codec.
     */
    public ParamCodec() {
        super(new Param());
    }

    @Override
    protected Object getFieldValue(Object obj, String fieldName) {
        Object fieldValue = super.getFieldValue(obj, fieldName);
        if (fieldName.equals("value") && fieldValue != null) {
            return fieldValue.toString();
        }
        return fieldValue;
    }

    @Override
    protected void setFieldValue(Object obj, String fieldName, Object value) {
        if (fieldName.equals("value") && value != null) {
            super.setFieldValue(obj, fieldName, new ParamValue(value.toString()));
        } else {
            super.setFieldValue(obj, fieldName, value);
        }
    }
}
